#ifndef CpMagneticFieldMap_h
#define CpMagneticFieldMap_h

#include <TNamed.h>
#include <TString.h>
#include <TFile.h>
#include <TTree.h>
#include <TH1.h>
#include <TH2.h>
#include <TH3.h>

#include "CpMagneticFieldMapObject.h"
#include <TF3.h>

class CpMagneticFieldMap : public TNamed {
  public:
    enum EAxis {
      kX = 0, kY, kZ,
      kLastAxis
    };

    enum EFillMethod {
      kFill = 0, kBinContent,
      kLastFillMethod
    };

    CpMagneticFieldMap(const char* name = "DefaultField", const char* title = "Default Field Title", TString rootFile = "");
    ~CpMagneticFieldMap();

    void      Reset();
    Bool_t    ImportFromTxtFile(TString infileName = "PMAll.txt", TString outfileName = "PMAll.root");

    Long64_t  FillHistogram(TH1* hist, Int_t indexMag, Int_t indexAxis, Double_t axisOneAfter, Double_t axisTwoAfter);
    Long64_t  FillHistogram(TH2* hist, Int_t indexMag, Int_t indexAxis1, Int_t indexAxis2, Double_t axisAfter);
    Long64_t  FillHistogram(TH3* hist, Int_t indexMag);

    Bool_t    VerifyDataWithFitFunction(TF3*fun, EAxis fieldAxis, Long64_t times = 1.0);

    void      CloseOutputFile() { fOutFile->Close(); };
    TString   GetMagneticMapRootFileName() { return fMagneticMapRootFileName; }
    void      SetMagneticMapRootFileName(TString s) { fMagneticMapRootFileName = s; }

  private:

    TString                   fMagneticMapRootFileName;
    TFile                     *fOutFile;
    TTree                     *fTree;
    CpMagneticFieldMapObject  *fMagFieldObj;

    Bool_t    OpenMagneticMapRootFile(TString fileName = "");

    ClassDef(CpMagneticFieldMap, 1);


};

#endif
